package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Sysnotice;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ISysnoticeService;
import cn.wolfcode.trip.base.service.ISyspushService;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("sysnotice")
public class SysnoticeController {

    @Autowired
    private ISysnoticeService sysnoticeService;
    @Autowired
    private ISyspushService syspushService;

    @RequestMapping("list")
    public String list(Model model ,@ModelAttribute("qo") QueryObject qo){
        model.addAttribute("result",sysnoticeService.query(qo));
        return "sysnotice/list";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult list(Sysnotice sysnotice){
        JSONResult result = new JSONResult();
        try {
            sysnoticeService.save(sysnotice);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    @RequestMapping("getContentByNoticeId")
    @ResponseBody
    public Object getContentByNoticeId(Long noticeId){
        return syspushService.getContentByNoticeId(noticeId);
    }
}
